(function() {
	var skill = {
		save: function() {
			db.update(config.dbname.tag, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.tag, this._id);
		},
		getDetail: function(options) {
			var self = $Object.clone(this);
			self.detail_content = this.getGoods(null, null, options);
			return self;
		},
		_getGoodsIdList: function(options) {
			var content = this.content || (this.content = []);
			if (!(options && options.show_un_sold_goods)) {
				var bus = BusCon.get(this.bus_id);
				content = bus._filter_un_sold_goods(content);
			}
			return content;
		},
		//获取标签详情
		getGoods: function(num, page, options) {
			//模块循环依赖，延迟载入
			GoodsCon || (GoodsCon = require("../goods/_con"));
			var content = this._getGoodsIdList(options);
			content = data_cut.page(content, num, page);
			var result = [];
			var new_content = [];
			content.forEach(function(goods_id, index) {
				var goods = GoodsCon.get(goods_id);
				if (goods) {
					result.push(goods);
					new_content.push(goods_id);
				}
			});
			//如果有冗余项，重置
			if (new_content.length !== content.length) {
				this.content = new_content;
				this.save();
			}
			return result;
		},
		//非安全，添加商品
		_addGoods: function(goods_id) {
			var content = this.content || (this.content = []);
			if (content.indexOf(goods_id) === -1) {
				content.push(goods_id);
				this.save();
			}
		},
		//非安全，移除标签中的商品
		_removeGoods: function(goods_id) {
			var content = this.content || (this.content = []);
			var index = content.indexOf(goods_id);
			if (index === -1) {
				throwCusError("商品不属于指定标签")
			}
			content.splice(index, 1);
			this.save();
		},
		//非安全，标签重命名
		_rename: function(new_tag_name) {
			if (!helper.folder_name(new_tag_name)) {
				throwCusError("标签名命名不规范");
			}
			this.tag_name = new_tag_name;
			this.save();
		}
	}
	module.exports = skill;

	var db = require("../db/index");
	var UserCon = require("./_con");
	var BusCon = require("../bus/_con");
	var GoodsCon; // = require("../goods/_con");
	var AchCon = require("../ach/_con");
	var PayAchCon = require("../pay_ach/_con");
	var CommentCon = require("../comment/_con");
	var EvaluationCon = require("../eval/_con")
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var $Array = require("../_include/$.Array");
	var $Object = require("../_include/$.Object");
	var helper = require("../_include/helper");


}());